package com.zff.rental.utils.sql;

import lombok.Getter;

/**
 * @author HCY
 */
@Getter
public class Column {
    /**
     * 表别名
     */
    private final String tableAlias;

    /**
     * 列名
     */
    private final String column;

    private Column(String tableAlias, String column) {
        this.tableAlias = tableAlias;
        this.column = column;
    }

    private Column(String column) {
        this.tableAlias = null;
        this.column = column;
    }

    public static Column of(String tableAlias, String column) {
        return new Column(tableAlias, column);
    }

    public static Column of(String column) {
        return new Column(column);
    }

    public String toSqlColumn() {
        if (tableAlias == null) {
            return column;
        } else {
            return tableAlias + "." + column;
        }
    }
}
